package cn.microservices.cloud.common.mybtis.core.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.stereotype.Component;

/**
 * mybaits 自定义主键生成器
 */
@Component // 加入到spring容器中
public abstract class MybatisKeyGenerator implements IdentifierGenerator {

   @Override
   public Number nextId(Object entity) {
       Snowflake snowflake = IdUtil.getSnowflake(1, 1);
       long uid =  snowflake.nextId();
       return uid;
   }

}
